package com.cskaoyan.service;

import com.cskaoyan.bean.Log;
import com.cskaoyan.bean.LogListBean;
import com.cskaoyan.bean.params.AdminListBO;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.mapper.LogMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @USER: cuiweiguo#
 * @DATE: 2022/5/6
 * @TIME: 18:58
 * @PROJECT_NAME: mallproject2
 */
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    LogMapper logMapper;

    @Override
    public LogListBean queryLogList(BaseParam baseParam, String name) {
        //查询总共所有的数量
        Integer page = baseParam.getPage();//页码
        Integer limit = baseParam.getLimit();//数据量
        String sort = baseParam.getSort();//排序列
        String order = baseParam.getOrder();//desc\asc
        //分页插件 PageHelper，辅助我们做分页以及分页信息的获得
        PageHelper.startPage(page, limit);
        //执行查询过程中拼接分页信息
        //  username="%"+username+"%";
        List<Log> list = logMapper.select(sort, order,name);

        //total、pages、list
        //通过PageHelper帮我们来获得一些和分页相关的信息PageInfo
        //使用其有参构造方法 → 形参写来源于数据库的list
        PageInfo<Log> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return LogListBean.data(total, pages, limit, page, list);
    }

    @Override
    public void insertLog(Log log) {
        logMapper.insertSelective(log);
    }
}
